package com.scjst.controller;

import com.scjst.entity.UserEntity;
import com.scjst.mapper.UserMapper;
import com.scjst.service.UserService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class UserController {
    @Autowired
    private UserService userservice;

    @RequestMapping("/addUser")
    @ResponseBody
    public String addUser(UserEntity ue) {
       Integer rowCount=userservice.addUser(ue.getId(),ue.getName(),ue.getAge());
       return rowCount>0 ? "成功":"失败";
    }


    @RequestMapping("/findAlluser")
    @ResponseBody
    public String findAlluser() {
        List<UserEntity> allUser = userservice.findAllUser();
        String str="";
        for (UserEntity userEntity:allUser)
        {
            str+=userEntity.toString();
        }
        return  str;
    }
    @RequestMapping("/userList")
    public String userList(Model model) {
        List<UserEntity> allUser = userservice.findAllUser();
        model.addAttribute("allUserList",allUser);
        return  "UserList";
    }

}
